import { EnumBetResult, EnumBjlResult } from "@/models/enums/EnumBjlResult";
import { RecmInfo, RoundInfo } from "../ExecutePlan";
import { IRecmStrategy } from "../IRecmStrategy";

export interface IArrayOption {
    betArray: Array<EnumBjlResult>;
}
/**
 * 固定图形策略
 */
export class ArrayStrategy implements IRecmStrategy {
    /**
     * 配置
     */
    option: IArrayOption;
    strategyName: string = "ArrayStrategy";
    debugCompoenent: string = "ArrayStrategyDebug";
    /**
     * 构造函数
     */
    constructor(option?: IArrayOption) {
        if (option) {
            this.option = option;
        }
        else {
            this.option = { betArray: [] };
        }

    }
    resetRecm(): void {
    }
    copyValue(valueObj: any): void {
        let obj = valueObj as ArrayStrategy;
        if (obj) {
            this.strategyName = obj.strategyName;
            this.debugCompoenent = obj.debugCompoenent;
            Object.assign(this.option, obj.option);
        }

    }
    setResult(roundInfo: RoundInfo, recmInfo: RecmInfo, multiple: number, waterRate: number, fuliRate: number): void {

        return;
    }

    setOption(option: any): void {
        this.option = option as IArrayOption;
        if (!this.option) throw new Error("【固定图形策略】参数不正确");
    }
    toResult(roundInfo: RoundInfo): EnumBjlResult {
        let count = roundInfo.results.length;
        let index = count % this.option.betArray.length;
        return index >= 0 ? this.option.betArray[index] : EnumBjlResult.U;
    }
    getRecmArray() {
        return this.option.betArray;
    }
}
export interface IArrayIndexOption {
    betArray: Array<EnumBjlResult>;
    reset: number;
}
export class ArrayIndexStrategy implements IRecmStrategy {
    index: number = 0;
    /**
        * 配置
        */
    option: IArrayIndexOption;
    strategyName: string = "ArrayStrategy";
    debugCompoenent: string = "ArrayStrategyDebug";
    /**
     * 构造函数
     */
    constructor(option?: IArrayIndexOption) {
        if (option) {
            this.option = option;
        }
        else {
            this.option = { betArray: [], reset: 0 };
        }
        this.index = 0;
    }
    resetRecm(): void {
        this.index = 0;
    }
    copyValue(valueObj: any): void {
        let obj = valueObj as ArrayIndexStrategy;
        if (obj) {
            this.strategyName = obj.strategyName;
            this.debugCompoenent = obj.debugCompoenent;
            this.index = obj.index;
        }

    }
    setResult(roundInfo: RoundInfo, recmInfo: RecmInfo, multiple: number, waterRate: number, fuliRate: number): void {

        return;
    }

    toResult(roundInfo: RoundInfo): EnumBjlResult {
        if (roundInfo.recmResult == EnumBetResult.Success && this.option.reset > 0) {
            this.index = 0;
        }
        else if (roundInfo.recmResult == EnumBetResult.Fail && this.option.reset < 0) {
            this.index = 0;
        }
        let index = this.index % this.option.betArray.length;
        //return index >= 0 ? this.option.betArray[index] : EnumBjlResult.U;
        let recmV = EnumBjlResult.U;
        if (index >= 0) {
            this.index++;
            recmV = this.option.betArray[index];
        }
        return recmV;
    }
}